<!--
 * @FilePath     : /study_code/layui/21-10.html
 * @Description  : 导航 事件监听
 * @Date         : 2025-04-15 14:32:20
 * @Author       : Fang YingGui
 * @LastEditors  : fangyinggui 18715384437@163.com
 * @LastEditTime : 2025-04-15 14:39:12
-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>documentName</title>
    <link rel="stylesheet" href="/layui/dist/css/layui.css" />
  </head>
  <body>
    <ul class="layui-nav" lay-filter="demo-filter-nav">
      <li class="layui-nav-item layui-this"><a href="javascript:;">选中</a></li>
      <li class="layui-nav-item">
        <a href="javascript:;">常规</a>
      </li>
      <!-- lay-unselect -->
      <li class="layui-nav-item"><a href="javascript:;">导航</a></li>
      <li class="layui-nav-item">
        <a href="javascript:;">子级</a>
        <dl class="layui-nav-child">
          <dd><a href="javascript:;">菜单1</a></dd>
          <dd><a href="javascript:;">菜单2</a></dd>
          <dd><a href="javascript:;">菜单3</a></dd>
        </dl>
      </li>
      <li class="layui-nav-item">
        <a href="javascript:;">选项</a>
        <dl class="layui-nav-child">
          <dd><a href="javascript:;">选项1</a></dd>
          <dd class="layui-this"><a href="javascript:;">选项2</a></dd>
          <dd><a href="javascript:;">选项3</a></dd>
        </dl>
      </li>
      <li class="layui-nav-item"><a href="javascript:;">演示</a></li>
    </ul>

    <script src="/layui/dist/layui.js"></script>
    <script>
      layui.use(['element'], function () {
        var element = layui.element,
          layer = layui.layer

        /**
         * @brief: 监听导航点击事件
         * @param {String} 'nav(demo-filter-nav)'
         *    nav 为导航事件固定值；
         *    filter 为导航容器属性 lay-filter 对应的值。
         * @param {function} callback(elem)
         *    elem {Object} 当前点击元素的 jq 对象。
         * @return {*}
         */
        // element.on('nav(filter)', callback(elem))

        element.on('nav(demo-filter-nav)', function (elem) {
          console.log(elem) // 得到当前点击的元素的 jq 对象
          layer.msg('当前点击项：' + elem.text())
        })
      })
    </script>
  </body>
</html>
